<template>
  <van-nav-bar v-if="props.type == 2" :title="renderTitle">
    <template #right>
      <van-icon name="search" size="18" @click="search" />
    </template>
  </van-nav-bar>

  <van-nav-bar
    v-else="props.type == 1"
    :title="renderTitle"
    left-text="返回"
    left-arrow
    @click-left="onClickLeft"
  >
    <template #right>
      <van-icon name="search" size="18" @click="search" />
    </template>
  </van-nav-bar>
</template>

<script setup>
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import { useRouter } from 'vue-router';

const route = useRoute();
const router = useRouter();
const props = defineProps({
  type: {
    default: 1,
  },
  goodName: {
    default: '',
  },
});
const renderTitle = computed(() => {
  return route.meta.name ? route.meta.name : props.goodName;
});
const onClickLeft = () => history.back();
const search = () => {
  router.push('/search');
};
</script>

<style lang="scss" scoped></style>
